package com.example.wan_android.http.code

import android.util.Log
import com.example.wan_android.http.RetrofitClient
import com.example.wan_android.http.bean.PaperInfoData

class PaperRepository {
    suspend fun fetchPaperInfoData(page: Int): Result<List<PaperInfoData>> {
        try {
            val response = RetrofitClient.instance.getPapers(page)
            if (response.isSuccessful && response.body()?.errorCode == 0) {
                return Result.success(response.body()?.data?.datas ?: emptyList())
            } else {
                return Result.failure(Exception("Error: ${response.body()?.errorMsg}"))
            }
        } catch (e: Exception) {
            return Result.failure(e)
        }
    }
}